<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>setUnicode</title>
</head>

<body>
    <script>
        const setUnicode = text => {
            if (typeof text !== 'string' || !text.length) {
                return '';
            }
            let res = '';
            for (let i = 0, len = text.length; i < len; i++) {
                res += '\\u' + text[i].charCodeAt(0).toString(16);
            }
            return res;
        };
        document.write(setUnicode('Hello,world!'))
    </script>
</body>

</html>